<template>
  <!--悬浮菜单-->
  <div class="memory-menu">
    <!-- how to buy 视频 -->
    <!-- <div class="cart-video">
      <img class="menu-video" src="@/assets/images/home/ic_homevedio.png" @click="videoShow" alt="" />
    </div> -->


    <div class="hand-menu">
      <div class="menu-tops">
        <div class="cart-sty">
          <router-link to="/user/shopping">
            <vue-ball ref="ball" :duration="400">
              <div class="cart-wrap" :class="{ 'is-heartBeat': heartBeat }" @animationend="transitioned">
                <span class="cart-num" v-if="cartNum > 0">{{
                  cartNum > 99 ? "99+" : cartNum
                }}</span>
                <img class="menu-logo" src="@/assets/images/public/default_cart.png" @click="carMet" alt="" />
              </div>
              <img slot="icon" class="cart-image" src="@/assets/images/public/default_cart.png" @click="carMet"
                alt="" />
            </vue-ball>
          </router-link>
        </div>
      </div>
      <div class="divider-sty"></div>
      <!-- 下载 -->
      <Poptip class="download-pop" placement="left-start" trigger="hover" padding="16px" v-model="visible">
        <div class="hand-menu-item rect-pop">
          <img class="menu-logo" src="@/assets/images/public/download.png" alt="">
        </div>
        <div class="float-rect" slot="content">
          <div v-for="(item, index) in codeArr" :key="index" class="rect-sty">
            <img :src="item.codeImg" class="code-sty" alt="">
            <div class="code-name">
              <img :src="item.logoImg" class="logo-icon" alt="">
              <span class="text">{{ item.name }}</span>
            </div>
          </div>
        </div>
      </Poptip>
      <div class="divider-sty"></div>
      <!-- 客服 -->
      <div class="hand-menu-item">
        <img src="@/assets/images/home/support.png" class="menu-logo" @click="showWidget" alt="">
      </div>
      <div class="hand-menu-item" v-for="item in config.supportList" :key="item.platform">
        <a v-if="item.platform == 'Discord'" class="discord" target="_blank" :href="item.account">
          <img class="menu-logo" @click="discordMet" :src="item.icon" alt="">
        </a>
        <Poptip class="poptip" v-if="item.platform != 'Discord'" placement="left" trigger="hover">
          <img class="menu-logo" :src="item.icon" alt="">
          <div class="poptip-content" slot="content">
            <a class="name" target="_blank" :href="item.account">{{ $t('home.onlineCustomerService') }}：{{ item.platform
            }}</a>
            <vue-qr v-if="item.account" class="qr-code-image" :size="300" :margin="0" :text="item.account"></vue-qr>
          </div>
        </Poptip>
      </div>
      <div class="divider-sty"></div>
      <div class="hand-menu-item" @click="scrollToTop">
        <img class="menu-logo" src="@/assets/images/public/back-top.png" alt="">
      </div>
    </div>
    <!-- <div class="discord-wrap">
     <template v-for="item in config.supportList">
       <a v-if="item.platform == 'Discord'" class="discord" :key="item.platform" target="_blank" :href="item.account">
         <img class="menu-logo" :src="item.icon" alt="">
       </a>
     </template>
</div> -->
    <!-- <div class="memory-video" v-if="showVideo == 1">
			<div class="video-div">
        <video class="video-play" :controls="true" @play="videoPlay">
          <source src="https://libcdn1.hahbuy.com/public/opb_20250428_intro.mp4?_t=1" type="video/mp4">
        Your browser does not support the video tag.
        </video>
				<div class="play-close">
					<img class="close-icon" src="@/assets/images/home/coupon_close_icon.png" @click="videoClose" alt="" />
				</div>
			</div> 
		</div> -->
  </div>
</template>

<script>
import { Ball as vueBall } from "@hyhello/vue-ball";
import { mapState } from "vuex";
import VueQr from 'vue-qr'
import { pointUser } from "@/common/point/api-hook";//打点日志
export default {
  name: "hand-menu",
  components: { VueQr, vueBall },
  data() {
    return {
      heartBeat: false,
      visible: false,
      codeArr: [
        {
          name: 'App Store',
          codeImg: require('@/assets/images/download/app_store_code.png'),
          logoImg: require('@/assets/images/download/app_store.png')
        },
        {
          name: 'Google play ',
          codeImg: require('@/assets/images/download/google_play_code.png'),
          logoImg: require('@/assets/images/download/google_play.png')
        }
      ],
      showVideo: 0,
    }
  },
  computed: {
    ...mapState({
      config: state => state.config.config,
      userInfo: state => state.user.userInfo,
      cartNum: (state) => state.user.cartNum, // 购物车数量
    }),
    inviteLink() {
      return `${this.config.webDomain}/register?inviteCode=${this.userInfo.inviteCode}`;
    },
  },
  // 默认打开网站就显示引流下载，3s后消失
  created() {
    // setTimeout(() => {
    //   this.visible = false;
    // }, 3000)
    this.showVideo = localStorage.getItem('HOME_VIDEO_SHOW') ? localStorage.getItem('HOME_VIDEO_SHOW') : 1;
  },
  methods: {
    carMet() {
      pointUser('actions', '2005');
    },
    discordMet() {
      pointUser('actions', '3001');
    },
    transitioned() {
      // 加入购物车
      this.heartBeat = false;
    },
    scrollToTop() {
      window.scrollTo({
        top: 0,
        behavior: 'smooth'
      });
    },
    showWidget() {
      if (window.ssq) {
        ssq.push('chatOpen')
      }
    },
    //视频播放
    videoPlay(e) {
      if (e.type == 'play') {
        pointUser('actions', '3005');
      }
    },
    //关闭视频
    videoClose() {
      this.showVideo = 2;
      localStorage.setItem('HOME_VIDEO_SHOW', 2);
    },
    //显示视频
    videoShow() {
      this.showVideo = 1;
      localStorage.setItem('HOME_VIDEO_SHOW', 1);
    }
  }

}
</script>

<style scoped lang="less">
.memory-menu {
  position: fixed;
  right: 0;
  bottom: 5%;
  z-index: 100;


  .memory-video {
    position: fixed;
    right: 120px;
    bottom: 5%;
    width: 536px;
    height: 302px;
    border-radius: 2px;
    background: #FFFFFF;

    .video-play {
      width: 534px;
      height: 300px;
    }

    .video-div {
      width: 100%;
      height: 100%;
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;

      .play-close {
        width: 24px;
        height: 24px;
        position: absolute;
        top: 16px;
        right: 16px;
        z-index: 200;
        cursor: pointer;

        .close-icon {
          width: 24px;
          height: 24px;
        }
      }
    }
  }

  .menu-tops {
    width: 60px;
    background: #FFFFFF;
    z-index: 100;
    overflow: hidden;
  }

  .cart-video {
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .menu-video {
    width: 81px;
    height: 81px;
    cursor: pointer;
    margin-bottom: 8px;
    margin-left: -8px;
  }

  .video-mb8 {
    margin-bottom: 8px;
  }

  .cart-sty {
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;

    .cart-wrap {
      position: relative;

      .menu-logo {
        display: block;
        width: 30px;
        height: 30px;
        cursor: pointer;
      }

      .cart-num {
        position: absolute;
        right: -8px;
        top: -8px;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 18px;
        height: 18px;
        background: @error-color;
        border-radius: 50%;
        color: #ffffff;
        font-size: 12px;
        font-weight: 500;
        transform: scale(0.8);
      }
    }
  }

  .divider-sty {
    width: 48px;
    height: 2px;
    background: #EFEFEF;
    border-radius: 10px 10px 10px 10px;
    margin: 0 auto;
  }

  .hand-menu {
    // position: fixed;
    // right: 30px;
    // top: 50%;
    // transform: translateY(-50%);
    width: 60px;
    z-index: 100;
    background: #FFFFFF;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
    border-radius: 15px 0px 0px 15px;
    overflow: hidden;
    padding-top: 10px;



    .download-pop {
      :deep(.ivu-poptip-arrow) {
        display: none;
      }

      :deep(.ivu-poptip-inner) {
        border-radius: 8px;
      }

      .hand-menu-item {
        text-align: center;

        .menu-logo {
          width: 32px;
          height: 32px;
          font-size: 24px;
          margin-bottom: 16px;
          margin-top: 9px;
        }
      }

      .rect-pop {
        width: 60px;
        height: 60px;
        cursor: pointer;
        padding-top: 16px;
      }

      .float-rect {
        display: flex;
        gap: 16px;

        .rect-sty {
          padding: 10px 10px 12px 10px;
          background: #F6F6F6;
          border-radius: 8px 8px 8px 8px;
          border: 1px solid #F1F1F1;

          .code-sty {
            width: 114px;
            height: 114px;
          }

          .code-name {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 4px;

            .logo-icon {
              width: 16px;
              height: 16px;
            }

            .text {
              font-family: PingFang SC, PingFang SC;
              font-weight: 600;
              font-size: 14px;
              color: #1E1714;
              line-height: 18px;
            }
          }
        }
      }

    }

    .hand-menu-item {
      text-align: center;

      &:first-child {
        border-top: 0;
      }

      .menu-logo {
        width: 32px;
        height: 32px;
        font-size: 24px;
        cursor: pointer;
        margin-bottom: 16px;
        margin-top: 9px;
      }

      .poptip {
        .poptip-content {
          width: 150px;

          .name {
            display: block;
            white-space: pre-wrap;
            overflow: hidden;
            margin-bottom: 6px;
            color: @t-title-color;
            font-size: 14px;

            &:hover {
              color: @primary-color
            }
          }

          .qr-code-image {
            width: 100%;
          }
        }
      }
    }

  }

  .discord-wrap {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 999;

    .menu-logo {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      overflow: hidden;
    }
  }

  .is-heartBeat {
    animation-name: heartBeat;
    animation-duration: 1s;
    animation-timing-function: ease-in-out;
  }

  .cart-image {
    display: block;
    width: 24px;
    height: 24px;
  }

  @keyframes heartBeat {
    0% {
      -webkit-transform: scale(1);
      transform: scale(1);
    }

    14% {
      -webkit-transform: scale(1.2);
      transform: scale(1.2);
    }

    28% {
      -webkit-transform: scale(1);
      transform: scale(1);
    }

    42% {
      -webkit-transform: scale(1.2);
      transform: scale(1.2);
    }

    70% {
      -webkit-transform: scale(1);
      transform: scale(1);
    }
  }
}
</style>